<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>流程实例信息列表</title>
<link href="../../static/plugin/easyui/themes/bootstrap/easyui.css"
	rel="stylesheet" type="text/css" />
<link href="../../static/plugin/easyui/themes/icon.css" rel="stylesheet"
	type="text/css" />
<script src="../../static/plugin/easyui/jquery.min.js"
	type="text/javascript"></script>
<script src="../../static/plugin/easyui/jquery.easyui.min.js"
	type="text/javascript" charset="utf-8"></script>
<script src="../../static/plugin/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js"
	type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js"
	type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js"
	type="text/javascript"></script>
<script src="../../ffres/dict/all.js" type="text/javascript"></script>
<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<style>
	.task-tree-icon {
		background: url('../../static/img/tree/nodepic.gif') no-repeat 0
	}
</style>
<script type="text/javascript">
	$(function() {
		var batchId = $.getUrlParam('batchId');
		$("#taskTree").tree(
				{
					url : '../../api/bat/inst/task/tree/' + batchId,
					method : 'get',
					animate : true,
					onSelect : function(node) {
						buttomDisable(node.attributes);
					},
					formatter : function(node) {
						if (node.attributes) {
							node.iconCls = 'task-tree-icon';
							var taskInfo = node.attributes;
							return '<span style="color:'
									+ getColor(taskInfo.taskRunState) + '">'
									+ node.text + '</span>';
						} else {
							return node.text;
						}
					}
				});

		$("#dg").datagrid({
			singleSelect : true,
			collapsible : true,
			url : '../../api/bat/inst/tasks',
			queryParams : {
				batchId : batchId,
				startTimeNotNull : true
			},
			method : 'post',
			toolbar : "#tb",
			title : "",
			rownumbers : true,
			pagination : true,
			pageSize : "20"
		});
		//装载信息tab页
		$("#dg2").datagrid({
			singleSelect : true,
			collapsible : true,
			url : '../../api/plugin/load/results',
			queryParams : {
				batchId : batchId,
				startTimeNotNull : true
			},
			method : 'post',
			toolbar : "#tb2",
			title : "",
			rownumbers : true,
			pagination : true,
			pageSize : "20"
		});
		timeRefresh(true);
	});

	function getColor(taskRunState) {
		var color = "";
		if (taskRunState == 7) {
			color = "red";
		} else if (taskRunState == 2) {
			color = "#40a0ff";
		} else if (taskRunState == 4 || taskRunState == 3) {
			color = "#FFDA44";
		} else if (taskRunState == 1) {
			color = "#c000ff";
		} else if (taskRunState == 6) {
			color = "#00cc00";
		} else if (taskRunState == 0) {
			color = "#000000";
		}
		return color;
	}

	function buttomDisable(taskInfo) {
		if (taskInfo.taskInterveneState == 0 && taskInfo.taskRunState < 6) {
			$("#taskHangUp").linkbutton("enable");
		} else {
			$("#taskHangUp").linkbutton("disable");
		}

		if (taskInfo.taskInterveneState == 2) {
			$("#taskHangDown").linkbutton("enable");
		} else {
			$("#taskHangDown").linkbutton("disable");
		}

		if (taskInfo.taskRunState != 6 && taskInfo.taskInterveneState != 1) {
			$("#taskSkip").linkbutton("enable");
		} else {
			$("#taskSkip").linkbutton("disable");
		}

		if (taskInfo.taskRunState == 7) {
			$("#taskAgainRun").linkbutton('enable');
		} else {
			$("#taskAgainRun").linkbutton('disable');
		}

		if ((taskInfo.taskRunState == 2 || taskInfo.taskRunState == 3 || taskInfo.taskRunState == 4)
				&& taskInfo.taskInterveneState != 3) {
			$("#taskExit").linkbutton('enable');
		} else {
			$("#taskExit").linkbutton('disable');
		}
	}

	function timeRefresh(first) {
		if (!first) {
			$("#dg").datagrid('reload');
			$("#taskTree").tree('reload');
		}
		window.setTimeout("timeRefresh()", 5 * 1000);
	}

	function doView() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情', 'BatInstTaskView.html?' + 'batchId='
					+ row.batchId + '&batchOrder=' + row.batchOrder
					+ '&taskId=' + row.taskId);
		} else {
			$.messager.alert('提示', '请选择一条记录！', 'info');
		}
	}
	/*查询日志信息*/
	function doPluginExecLogList() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			//打开新页面
			JLEUtil.createModalWin('日志信息','PluginExecLogList.html?' + 'batchSerialNo='
					+ row.batchSerialNo + '&taskId=' + row.taskId);
		} else {
			$.messager.alert('提示', '请选择一条记录！', 'info');
		}
	}

	//修改
	function doUpdateBatInstTask() {
		var node = $("#taskTree").tree('getSelected');
		if (node && node.attributes) {
			JLEUtil.createModalWin('修改', 'BatInstTaskUpdate.html?'
					+ '&batchId=' + node.attributes.batchId + '&batchOrder='
					+ node.attributes.batchOrder + '&taskId='
					+ node.attributes.taskId);
		} else {
			$.messager.alert('提示', '请选择一条任务！', 'info');
		}
	}

	//挂起
	function doTaskHangUp() {
		var node = $("#taskTree").tree('getSelected');
		if (node && node.attributes) {
			$.messager.confirm('提示', '是否确认要挂起任务？', function(r) {
				if (r) {
					var taskInfo = node.attributes;
					$.restfulPut('../../api/bat/inst/task/hangup', taskInfo,
							function(data) {
								if (data.code == 0) {
									$.messager.alert('提示', '挂起成功！', 'success');
								} else {
									$.messager.alert('提示', '挂起失败！', 'error');
								}
							})
				}
			});
		} else {
			$.messager.alert('提示', '请选择一条任务！', 'info');
		}
	}

	//解挂
	function doTaskHangDown() {
		var node = $("#taskTree").tree('getSelected');
		if (node && node.attributes) {
			$.messager.confirm('提示', '是否确认要解挂任务？', function(r) {
				if (r) {
					var taskInfo = node.attributes;
					$.restfulPut('../../api/bat/inst/task/hangdown', taskInfo,
							function(data) {
								if (data.code == 0) {
									$.messager.alert('提示', '解挂成功！', 'success');
								} else {
									$.messager.alert('提示', '解挂失败！', 'error');
								}
							})
				}
			});
		} else {
			$.messager.alert('提示', '请选择一条任务！', 'info');
		}
	}

	//置过
	function doTaskSkip() {
		var node = $("#taskTree").tree('getSelected');
		if (node && node.attributes) {
			$.messager.confirm('提示', '是否确认要置过任务？', function(r) {
				if (r) {
					var taskInfo = node.attributes;
					$.restfulPut('../../api/bat/inst/task/skip', taskInfo,
							function(data) {
								if (data.code == 0) {
									$.messager.alert('提示', '置过成功！', 'success');
								} else {
									$.messager.alert('提示', '置过失败！', 'error');
								}
							})
				}
			});
		} else {
			$.messager.alert('提示', '请选择一条任务！', 'info');
		}
	}
	//装载信息查看
	function doView1(){
		var row = $('#dg2').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情','PluginLoadResultView.html?' + 'batchSerialNo=' + row.batchSerialNo + '&tableName=' + row.tableName);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
	
</script>
</head>
<body class="easyui-layout" style="padding: 10px">
	<div data-options="region:'north',split:true"
		style="width: 100%; height: 35px; background: #F4F4F4;">
		<div style="margin-bottom: 2px">
			<a href="javascript:doUpdateBatInstTask()" id="updateBatInstTask"
				class="easyui-linkbutton" iconCls="icon-ok" plain="true">修改</a> <a
				href="javascript:doTaskHangUp()" id="taskHangUp"
				class="easyui-linkbutton" iconCls="icon-ok" plain="true">挂起</a> <a
				href="javascript:doTaskHangDown()" id="taskHangDown"
				class="easyui-linkbutton" iconCls="icon-ok" plain="true">解挂</a> <a
				href="javascript:doTaskSkip()" id="taskSkip"
				class="easyui-linkbutton" iconCls="icon-ok" plain="true">置过</a> <a
				href="javascript:doTaskAgainRun()" id="taskAgainRun"
				class="easyui-linkbutton" iconCls="icon-ok" plain="true"
				style="display: none;">重跑</a> <a href="javascript:doTaskExit()"
				id="taskExit" class="easyui-linkbutton" iconCls="icon-ok"
				plain="true" style="display: none;">退出</a> <span
				style="color: #40a0ff">蓝色:执行中 </span> <span style="color: #000000">
				| </span> <span style="color: #c000ff"> 紫色:待执行 </span> <span
				style="color: #000000"> | </span> <span style="color: #00cc00">
				绿色:执行成功 </span> <span style="color: #000000"> | </span> <span
				style="color: #FFDA44"> 橙色:警告 </span> <span style="color: #000000">
				| </span> <span style="color: red"> 红色:执行失败 </span>
		</div>
	</div>
	<div data-options="region:'west',split:true"
		style="height: 100%; width: 20%; background: #F4F4F4;">
		<ul id="taskTree"></ul>
	</div>
	<div data-options="region:'center',split:true"
		style="height: 100%; width: 80%;">
		<div id="tabs" class="easyui-tabs" data-options="fit:true"
			style="width: 100%;">
			<div title="任务执行信息" style="margin-top: 1px">
				<div id="tb" style="padding: 1px">
					<div style="margin-bottom: 2px">
						<a href="javascript:doView()" class="easyui-linkbutton"
							iconCls="icon-ok" plain="true">查看</a> <a
							href="javascript:doPluginExecLogList()" class="easyui-linkbutton"
							iconCls="icon-ok" plain="true">任务日志</a>
					</div>
				</div>
				<table id="dg" style="height: 100%;">
					<thead>
						<tr>
							<th data-options="field:'taskId',resizable:true">任务编号</th>
							<th data-options="field:'taskName',resizable:true">任务名称</th>
							<th data-options="field:'taskRunState',resizable:true"
								formatter="formatter_BAT_TASK_RUN_STATE">任务执行状态</th>
							<th data-options="field:'taskInterveneState',resizable:true"
								formatter="formatter_BAT_TASK_INTERVENE_STATE">任务干预状态</th>
							<th data-options="field:'startTime',resizable:true">启动时间</th>
							<th data-options="field:'endTime',resizable:true">结束时间</th>
							<th data-options="field:'costTime',resizable:true">运行时长（秒）</th>
							<th
								data-options="field:'batchSerialNo',resizable:true,hidden:true">流程流水号</th>
						</tr>
					</thead>
				</table>
			</div>
			<div title="数据装载信息">
				<div id="tb2" style="padding: 1px">
					<form id="searchForm">
						<table>
							<tr>
								<td>&nbsp;流程流水号：</td>
								<td><input name="batchSerialNo" id="batchSerialNo" /></td>
								<td>&nbsp;数据库表名：</td>
								<td><input name="tableName" id="tableName" /></td>
								<td><a class="easyui-linkbutton" href="javascript:void(0);"
									onclick="JLEUtil.queryForm('searchForm','dg2','../../api/plugin/load/results');">查找</a></td>
								<td><a class="easyui-linkbutton" href="javascript:void(0);"
									onclick="JLEUtil.clearForm('searchForm');">清空</a></td>
							</tr>
						</table>
					</form>
					<div style="margin-bottom: 2px">
						<a href="javascript:doView1()" class="easyui-linkbutton"
							iconCls="icon-ok" plain="true">查看</a>
					</div>
				</div>
				<table id="dg2" style="height: 100%">
					<thead>
						<tr>
							<th data-options="field:'batchSerialNo',resizable:true">流程流水号</th>
							<th data-options="field:'batchDate',resizable:true">流程日期</th>
							<th data-options="field:'tableName',resizable:true">数据库表名</th>
							<th data-options="field:'tableCnname',resizable:true">表中文名称</th>
							<th data-options="field:'tableType',resizable:true">数据表类型</th>
							<th data-options="field:'upSysname',resizable:true">供数系统名称</th>
							<th data-options="field:'tableLoadMode',resizable:true"
								formatter="formatter_BAT_TABLE_LOAD_MODE">数据装载方式</th>
							<th data-options="field:'loadFromFile',resizable:true">文件路径</th>
							<th data-options="field:'fileSize',resizable:true">文件大小</th>
							<th data-options="field:'startTime',resizable:true">启动时间</th>
							<th data-options="field:'endTime',resizable:true">结束时间</th>
							<th data-options="field:'costTime',resizable:true">运行时长</th>
							<th data-options="field:'readRows',resizable:true">读入条数</th>
							<th data-options="field:'loadRows',resizable:true">装入条数</th>
							<th data-options="field:'rejectRows',resizable:true">拒绝条数</th>
							<th data-options="field:'remark',resizable:true">备注</th>
							<th data-options="field:'loadResult',resizable:true"
								formatter="formatter_BAT_EXEC_RESULT">导数结果</th>
							<th data-options="field:'batchId',resizable:true">流程标识</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</div>
</body>
</html>
